#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    //this->setMouseTracking(true);

    // 开启定时器
    timerID = this->startTimer(1000);
}

Widget::~Widget()
{
    delete ui;
}

// 鼠标移动(这是一个低效操作，Qt默认不对鼠标移动进行追踪，需要进行第10行设置才能使用)
void Widget::mouseMoveEvent(QMouseEvent *event)
{
    qDebug() << "mouseMoveEvent:" << "(" << event->x() << "," << event->y()
             << "),(" << event->globalX() << "," << event->globalY() << ")";
}
// 滚轮滑动
void Widget::wheelEvent(QWheelEvent *event)
{
    qDebug() << "wheelEvent:" << event->delta();
}
// 键盘点击
void Widget::keyPressEvent(QKeyEvent *event)
{
//    qDebug() << "keyPressEvent:" << event->key();
    // 组合键
    if(event->key() == Qt::Key_A && event->modifiers() == Qt::ControlModifier)
        qDebug() << "Ctrl + A";
}
// 定时器
void Widget::timerEvent(QTimerEvent *event)
{
    // 如果有多个定时器，用timerID区分
    if(event->timerId() != this->timerID)
        return;
    else
    {
        int value = ui->lcdNumber->value();
        if(value <= 0)
        {
            killTimer(this->timerID);
            return;
        }
        else
        {
            --value;
            ui->lcdNumber->display(value);
        }
    }
}
// 移动窗口
void Widget::moveEvent(QMoveEvent *event)
{
    qDebug() << "moveEvent" << event->pos() << "," << event->oldPos();
}
// 改变窗口大小
void Widget::resizeEvent(QResizeEvent *event)
{
    qDebug() << "resizeEvent" << event->size();
}

